using System;
using System.Windows.Forms;

using FreeFlow.Administration;

namespace FreeFlowAdministrator
{
	/// <summary>
	/// Summary description for LibraryAdaptor.
	/// </summary>
	public class LibraryAdaptor : Adaptor, IDeletable
	{
    private Library library;
		public LibraryAdaptor(Library library)
		{
      this.library = library;
		}

    public override int ImageIndex
    {
      get
      {
        return 1;
      }
    }

    public override void AddChildren(TreeNode node)
    {
      // versions
      TreeNode versionsNode = TreeNodeFactory.CreateTreeNode(new LibraryVersionsAdaptor(library.Versions));
      node.Nodes.Add(versionsNode);
    }

    public override string Text
    {
      get
      {
        return library.Name;
      }
    }

    public override Control GetRenderer()
    {
      LibraryControl control = new LibraryControl();
      control.LoadLibrary(library);
      control.ItemDeleted += new EventHandler(TriggerItemDeleted);
      return control;
    }

    public override object Object
    {
      get
      {
        return library;
      }
    }

    #region IDeletable Members

    public void Delete()
    {
      library.Delete();
    }

    #endregion
  }
}
